package com.ruoyi.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.dto.RoleDTO;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.TimeUtil;
import com.ruoyi.system.constants.DyRoleKeyConstants;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.bo.DyAnchorRelEditBo;
import com.ruoyi.system.domain.bo.DyCustomerSumBo;
import com.ruoyi.system.domain.bo.DyMemberCodeBo;
import com.ruoyi.system.domain.vo.DyAnchorCustomerVo;
import com.ruoyi.system.domain.vo.DyAnchorRelVo;
import com.ruoyi.system.domain.vo.DyCustomerVo;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.IDyCommonService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.domain.bo.DyAnchorBo;
import com.ruoyi.system.domain.vo.DyAnchorVo;
import com.ruoyi.system.service.IDyAnchorService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 主播Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-20
 */
@RequiredArgsConstructor
@Service
@Transactional(rollbackFor = Exception.class)
public class DyAnchorServiceImpl implements IDyAnchorService {

    private final DyAnchorMapper baseMapper;
    private final DyAnchorRelMapper dyAnchorRelMapper;
    private final DyCustomerMapper dyCustomerMapper;
    private final SysUserMapper sysUserMapper;
    private final SysDeptMapper sysDeptMapper;
    private final DyOrderMapper dyOrderMapper;

    @Resource
    IDyCommonService iDyCommonService;

    /**
     * 查询主播
     */
    @Override
    public DyAnchorVo queryById(Long id){
        DyAnchorVo result = baseMapper.selectVoById(id);

        LambdaQueryWrapper<SysDept> deptLambdaQueryWrapper = new LambdaQueryWrapper<>();
        deptLambdaQueryWrapper.eq(SysDept::getDeptId,result.getCompanyId());
        List<SysDept> deptList = sysDeptMapper.selectDeptList(deptLambdaQueryWrapper);
        if (CollectionUtil.isNotEmpty(deptList)){
            Map<Long,SysDept> deptMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId,item -> item,(k1,k2) -> k1));
            if (ObjectUtil.isNotEmpty(deptMap) && ObjectUtil.isNotEmpty(deptMap.get(result.getCompanyId()))){
                result.setCompanyName(deptMap.get(result.getCompanyId()).getDeptName());
            }
        }

        if (ObjectUtil.isNotEmpty(result)){
            LambdaQueryWrapper<DyAnchorRel> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(DyAnchorRel::getAnchorId,result.getId());
            List<DyAnchorRelVo> dyAnchorRelVos = dyAnchorRelMapper.selectVoList(queryWrapper);
            if (CollectionUtil.isNotEmpty(dyAnchorRelVos)){
                result.setDyAnchorRelVos(dyAnchorRelVos);

                List<Long> userIdList = dyAnchorRelVos.stream().map(DyAnchorRelVo::getRelId).collect(Collectors.toList());
                LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
                sysUserLambdaQueryWrapper.in(SysUser::getUserId,userIdList);
                List<SysUser> sysUserList = sysUserMapper.selectUserList(sysUserLambdaQueryWrapper);
                if (CollectionUtil.isNotEmpty(sysUserList)){
                    Map<Long,SysUser> sysUserMap = sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId,item -> item,(k1,k2) -> k1));
                    for (DyAnchorRelVo item : dyAnchorRelVos){
                        if (ObjectUtil.isNotEmpty(sysUserMap) && ObjectUtil.isNotEmpty(sysUserMap.get(item.getRelId()))){
                            item.setRelName(sysUserMap.get(item.getRelId()).getNickName());
                        }
                    }
                }

                Map<Long,List<DyAnchorRelVo>> listMap = dyAnchorRelVos.stream().collect(Collectors.groupingBy(DyAnchorRelVo::getAnchorId));
                if (ObjectUtil.isNotEmpty(listMap) && ObjectUtil.isNotEmpty(listMap.get(result.getId()))){
                    result.setDyAnchorRelVos(listMap.get(result.getId()));
                }
            }
        }
        return result;
    }

    /**
     * 查询主播列表
     */
    @Override
    public TableDataInfo<DyAnchorVo> queryPageList(DyAnchorBo bo, PageQuery pageQuery, LoginUser loginUser) {
        RoleDTO roleDTO = iDyCommonService.getFirstRole(loginUser.getRoles());
        if (ObjectUtil.isEmpty(roleDTO)){
            throw new ServiceException("无数据查看权限");
        }

        LambdaQueryWrapper<DyAnchor> lqw = buildQueryWrapper(bo);

        if (roleDTO.getRoleKey().equals(DyRoleKeyConstants.roleKeySubCompany)){
            lqw.eq(DyAnchor::getCompanyId,loginUser.getDeptId());

            RoleDTO roleDTO2 = iDyCommonService.getRoleByKey(loginUser.getRoles(),DyRoleKeyConstants.roleKeyYunYing);
            if (ObjectUtil.isNotEmpty(roleDTO2)){
//            LambdaQueryWrapper<SysUserRole> queryWrapperUserRole = new LambdaQueryWrapper<>();
//            queryWrapperUserRole.eq(SysUserRole::getRoleId,roleDTO2.getRoleId());
//            List<SysUserRole> userRoles = sysUserRoleMapper.selectList(queryWrapperUserRole);
//            if(CollectionUtil.isNotEmpty(userRoles)){
//                List<Long> userIds = userRoles.stream().map(SysUserRole::getUserId).collect(Collectors.toList());
//            }
                LambdaQueryWrapper<DyAnchorRel> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(DyAnchorRel::getRelId,loginUser.getUserId());
                List<DyAnchorRelVo> dyAnchorRels = dyAnchorRelMapper.selectVoList(queryWrapper);
                if (CollectionUtil.isNotEmpty(dyAnchorRels)){
                    List<Long> anchorIds = dyAnchorRels.stream().map(DyAnchorRelVo::getAnchorId).collect(Collectors.toList());
                    lqw.in(DyAnchor::getId,anchorIds);
                }
            }
        } else if(roleDTO.getRoleKey().equals(DyRoleKeyConstants.roleKeyYunYing)){
            LambdaQueryWrapper<DyAnchorRel> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(DyAnchorRel::getRelId,loginUser.getUserId());
            List<DyAnchorRelVo> dyAnchorRels = dyAnchorRelMapper.selectVoList(queryWrapper);
            if (CollectionUtil.isNotEmpty(dyAnchorRels)){
                List<Long> anchorIds = dyAnchorRels.stream().map(DyAnchorRelVo::getAnchorId).collect(Collectors.toList());
                lqw.in(DyAnchor::getId,anchorIds);
            }
        }


        lqw.eq(bo.getCustomerId() != null, DyAnchor::getCustomerId, bo.getCustomerId());
        lqw.orderByDesc(DyAnchor::getUpdateTime);
        Page<DyAnchorVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        if (CollectionUtil.isNotEmpty(result.getRecords())){
            buildDyAnchorVo(result.getRecords());
            buildDyAnchorSumVo(result.getRecords(), bo.getStartTime(), bo.getEndTime());
        }
        return TableDataInfo.build(result);
    }



    /**
     * 设置统计信息
     */
    private void buildDyAnchorSumVo(List<DyAnchorVo> list, Date startTime, Date endTime){
        List<Long> idList = list.stream().map(DyAnchorVo::getId).collect(Collectors.toList());
        List<DyAnchorCustomerVo> anchorCustomerVos = dyCustomerMapper.getSumAnchorsCustomer(idList, startTime, endTime);
        if (CollectionUtil.isNotEmpty(anchorCustomerVos)){
            Map<Long,DyAnchorCustomerVo> anchorCustomerVoMap =
                    anchorCustomerVos.stream().collect(Collectors.toMap(DyAnchorCustomerVo::getAnchorId,item -> item,(k1,k2) -> k1));
            for (DyAnchorVo item : list){
                if (ObjectUtil.isNotEmpty(anchorCustomerVoMap) && ObjectUtil.isNotEmpty(anchorCustomerVoMap.get(item.getId()))){
                    DyAnchorCustomerVo dyAnchorCustomerVo = anchorCustomerVoMap.get(item.getId());
                    if (ObjectUtil.isNotEmpty(dyAnchorCustomerVo) && ObjectUtil.isNotEmpty(dyAnchorCustomerVo.getLiveTime())){
                        BigDecimal liveTime = BigDecimal.valueOf(dyAnchorCustomerVo.getLiveTime()).divide(BigDecimal.valueOf(60),2, RoundingMode.HALF_UP);
                        item.setLiveTime(liveTime);
                    }
                    if (ObjectUtil.isNotEmpty(dyAnchorCustomerVo) && ObjectUtil.isNotEmpty(dyAnchorCustomerVo.getNum())){
                        item.setNum(dyAnchorCustomerVo.getNum());
                    }
                    if (ObjectUtil.isNotEmpty(dyAnchorCustomerVo) && ObjectUtil.isNotEmpty(dyAnchorCustomerVo.getGiftNum())){
                        item.setGiftNum(dyAnchorCustomerVo.getGiftNum());
                    }
                    if (ObjectUtil.isNotEmpty(dyAnchorCustomerVo) && ObjectUtil.isNotEmpty(dyAnchorCustomerVo.getOrderNum())){
                        item.setOrderNum(dyAnchorCustomerVo.getOrderNum());
                    }
                    if (ObjectUtil.isNotEmpty(dyAnchorCustomerVo) && ObjectUtil.isNotEmpty(dyAnchorCustomerVo.getArrivalsNum())){
                        item.setArrivalsNum(dyAnchorCustomerVo.getArrivalsNum());
                    }
                    BigDecimal orderNum = BigDecimal.valueOf(item.getOrderNum());
                    BigDecimal giftNum = BigDecimal.valueOf(item.getGiftNum());
                    if (orderNum.compareTo(BigDecimal.ZERO) > 0 && giftNum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal perTransForm = orderNum.divide(giftNum,2, RoundingMode.HALF_UP);
                        item.setPerTransForm(perTransForm);
                    }

                    BigDecimal arrivalsNum = BigDecimal.valueOf(item.getArrivalsNum());
                    if (arrivalsNum.compareTo(BigDecimal.ZERO) > 0 && giftNum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal perArrivals = arrivalsNum.divide(giftNum,2, RoundingMode.HALF_UP);
                        item.setPerArrivals(perArrivals);
                    }

                    List<DyOrder> orders = dyOrderMapper.selectList(new LambdaQueryWrapper<DyOrder>().eq(DyOrder::getAnchorId, item.getId()).eq(DyOrder::getOrderStatus, 1).orderByDesc(BaseEntity::getCreateTime));
                    if (!orders.isEmpty()){
                        List<DyOrder> orderList = orders.stream().filter(DyOrder::getComplaint).collect(Collectors.toList());
                        item.setComplaintRate(new BigDecimal(orderList.size()).divide(new BigDecimal(orders.size()), 6, RoundingMode.DOWN).multiply(new BigDecimal(100)).setScale(2, RoundingMode.DOWN));
                    }
                }
            }
        }
    }

    /**
     * 部门用户信息处理
     */
    private void buildDyAnchorVo(List<DyAnchorVo> list){
        List<Long> companyIdList = list.stream().map(DyAnchorVo::getCompanyId).collect(Collectors.toList());
        LambdaQueryWrapper<SysDept> deptLambdaQueryWrapper = new LambdaQueryWrapper<>();
        deptLambdaQueryWrapper.in(SysDept::getDeptId,companyIdList);
        List<SysDept> deptList = sysDeptMapper.selectDeptList(deptLambdaQueryWrapper);
        if (CollectionUtil.isNotEmpty(deptList)){
            Map<Long,SysDept> deptMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId,item -> item,(k1,k2) -> k1));
            for (DyAnchorVo item : list){
                if (ObjectUtil.isNotEmpty(deptMap) && ObjectUtil.isNotEmpty(deptMap.get(item.getCompanyId()))){
                    item.setCompanyName(deptMap.get(item.getCompanyId()).getDeptName());
                }
            }
        }

        List<Long> idList = list.stream().map(DyAnchorVo::getId).collect(Collectors.toList());
        LambdaQueryWrapper<DyAnchorRel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(DyAnchorRel::getAnchorId,idList);
        List<DyAnchorRelVo> dyAnchorRelVos = dyAnchorRelMapper.selectVoList(queryWrapper);

        if (CollectionUtil.isNotEmpty(dyAnchorRelVos)){
            List<Long> userIdList = dyAnchorRelVos.stream().map(DyAnchorRelVo::getRelId).collect(Collectors.toList());
            LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
            sysUserLambdaQueryWrapper.in(SysUser::getUserId,userIdList);
            List<SysUser> sysUserList = sysUserMapper.selectUserList(sysUserLambdaQueryWrapper);
            if (CollectionUtil.isNotEmpty(sysUserList)){
                Map<Long,SysUser> sysUserMap = sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId,item -> item,(k1,k2) -> k1));
                for (DyAnchorRelVo item : dyAnchorRelVos){
                    if (ObjectUtil.isNotEmpty(sysUserMap) && ObjectUtil.isNotEmpty(sysUserMap.get(item.getRelId()))){
                        item.setRelName(sysUserMap.get(item.getRelId()).getNickName());
                    }
                }
            }

            Map<Long,List<DyAnchorRelVo>> listMap = dyAnchorRelVos.stream().collect(Collectors.groupingBy(DyAnchorRelVo::getAnchorId));
            for (DyAnchorVo item : list){
                if (ObjectUtil.isNotEmpty(listMap) && ObjectUtil.isNotEmpty(listMap.get(item.getId()))){
                    item.setDyAnchorRelVos(listMap.get(item.getId()));
                }
            }
        }
    }

    /**
     * 查询主播列表
     */
    @Override
    public List<DyAnchorVo> queryList(DyAnchorBo bo) {
        LambdaQueryWrapper<DyAnchor> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<DyAnchor> buildQueryWrapper(DyAnchorBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<DyAnchor> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getName()), DyAnchor::getName, bo.getName());
        lqw.eq(bo.getCompanyId() != null, DyAnchor::getCompanyId, bo.getCompanyId());
        lqw.eq(bo.getCompanyPoint() != null, DyAnchor::getCompanyPoint, bo.getCompanyPoint());
        lqw.eq(StringUtils.isNotBlank(bo.getDes()), DyAnchor::getDes, bo.getDes());
        return lqw;
    }

    /**
     * 新增主播
     */
    @Override
    public Boolean insertByBo(DyAnchorBo bo) {
        DyAnchor add = BeanUtil.toBean(bo, DyAnchor.class);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        if (CollectionUtil.isNotEmpty(bo.getRelEditBoList())){
            List<DyAnchorRel> anchorRelList = new ArrayList<>();
            for (DyAnchorRelEditBo item : bo.getRelEditBoList()){
                DyAnchorRel dyAnchorRel = new DyAnchorRel();
                BeanUtil.copyProperties(item, dyAnchorRel);
                dyAnchorRel.setAnchorId(add.getId());
                anchorRelList.add(dyAnchorRel);
            }
            dyAnchorRelMapper.insertOrUpdateBatch(anchorRelList);
        }
        return flag;
    }

    /**
     * 修改主播
     */
    @Override
    public Boolean updateByBo(DyAnchorBo bo) {
        DyAnchor update = BeanUtil.toBean(bo, DyAnchor.class);
        validEntityBeforeEdit(update);
        if (CollectionUtil.isNotEmpty(bo.getRelEditBoList())){
            LambdaQueryWrapper<DyAnchorRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(DyAnchorRel::getAnchorId,bo.getId());
            dyAnchorRelMapper.delete(lambdaQueryWrapper);
            List<DyAnchorRel> anchorRelList = new ArrayList<>();
            for (DyAnchorRelEditBo item : bo.getRelEditBoList()){
                DyAnchorRel dyAnchorRel = new DyAnchorRel();
                BeanUtil.copyProperties(item,dyAnchorRel);
                dyAnchorRel.setAnchorId(bo.getId());
                anchorRelList.add(dyAnchorRel);
            }
            dyAnchorRelMapper.insertOrUpdateBatch(anchorRelList);
        }
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeEdit(DyAnchor entity){
        if (ObjectUtil.isEmpty(entity.getId())){
            throw new ServiceException("参数错误");
        }
    }

    @Override
    public DyAnchorCustomerVo getSumAnchorCustomer(DyCustomerSumBo customerSumBo) {
        DyAnchorCustomerVo dyAnchorCustomerVo = new DyAnchorCustomerVo();
        dyAnchorCustomerVo.setAnchorId(customerSumBo.getAnchorId());

        String anchorName = "";
        LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        sysUserLambdaQueryWrapper.eq(SysUser::getUserId,customerSumBo.getAnchorId());
        DyAnchorVo anchorVo = baseMapper.selectVoById(customerSumBo.getAnchorId());
        if (ObjectUtil.isNotEmpty(anchorVo)){
            anchorName = anchorVo.getName();
        } else {
            throw new ServiceException("无效的主播");
        }

        Date startTimeStart;
        Date startTimeEnd;
        if (ObjectUtil.isEmpty(customerSumBo.getDay())){
            startTimeStart = TimeUtil.getTimeMonthStart(customerSumBo.getYear(),customerSumBo.getMonth());
            startTimeEnd = TimeUtil.getTimeMonthEnd(customerSumBo.getYear(),customerSumBo.getMonth());
        } else {
            startTimeStart = TimeUtil.getTimeDayStart(customerSumBo.getYear(),customerSumBo.getMonth(),customerSumBo.getDay());
            startTimeEnd = TimeUtil.getTimeDayEnd(customerSumBo.getYear(),customerSumBo.getMonth(),customerSumBo.getDay());
        }
        LambdaQueryWrapper<DyCustomer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DyCustomer::getAnchorId,customerSumBo.getAnchorId());
        queryWrapper.between(DyCustomer::getStartTime,startTimeStart ,startTimeEnd);
//        queryWrapper.le(DyCustomer::getStartTime,startTimeEnd);
//        queryWrapper.ge(DyCustomer::getStartTime,startTimeStart);
        queryWrapper.orderByDesc(DyCustomer::getStartTime);
        List<DyCustomerVo> customerVos = dyCustomerMapper.selectVoList(queryWrapper);

        if (CollectionUtil.isNotEmpty(customerVos)){
            int totalGiftSum = 0;
            int totalNum = 0;
            int totalOrderNum = 0;
            int totalLiveTime = 0;
            int totalArrivalsNum = 0;

            for (DyCustomerVo item : customerVos){
                item.setAnchorName(anchorName);
                if (ObjectUtil.isNotEmpty(item.getGiftNum()) && item.getGiftNum() > 0){
                    BigDecimal orderNum = BigDecimal.valueOf(item.getOrderNum());
                    BigDecimal giftNum = BigDecimal.valueOf(item.getGiftNum());
                    if (orderNum.compareTo(BigDecimal.ZERO) > 0 && giftNum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal perTransForm = orderNum.divide(giftNum,2,BigDecimal.ROUND_HALF_UP);
                        item.setPerTransForm(perTransForm);
                    }
                    BigDecimal arrivalsNum = BigDecimal.valueOf(item.getArrivalsNum());
                    if (arrivalsNum.compareTo(BigDecimal.ZERO) > 0 && giftNum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal perArrival = arrivalsNum.divide(giftNum,2,BigDecimal.ROUND_HALF_UP);
                        item.setPerArrivals(perArrival);
                    }
                }
                if (ObjectUtil.isNotEmpty(item.getGiftNum())){
                    totalGiftSum = totalGiftSum + item.getGiftNum();
                }
                if (ObjectUtil.isNotEmpty(item.getNum())){
                    totalNum = totalNum + item.getNum();
                }
                if (ObjectUtil.isNotEmpty(item.getLiveTime())){
                    totalLiveTime = totalLiveTime + item.getLiveTime();
                }
                if (ObjectUtil.isNotEmpty(item.getOrderNum())){
                    totalOrderNum = totalOrderNum + item.getOrderNum();
                }
                if (ObjectUtil.isNotEmpty(item.getArrivalsNum())){
                    totalArrivalsNum = totalArrivalsNum + item.getArrivalsNum();
                }
            }
            dyAnchorCustomerVo.setCustomerVos(customerVos);
            dyAnchorCustomerVo.setGiftNum(totalGiftSum);
            dyAnchorCustomerVo.setNum(totalNum);
            dyAnchorCustomerVo.setOrderNum(totalOrderNum);
            dyAnchorCustomerVo.setLiveTime(totalLiveTime);
            dyAnchorCustomerVo.setArrivalsNum(totalArrivalsNum);

            if(totalGiftSum > 0){
                if (totalOrderNum > 0){
                    BigDecimal totalPerTransForm = BigDecimal.valueOf(totalOrderNum).divide(BigDecimal.valueOf(totalGiftSum),2,BigDecimal.ROUND_HALF_UP);
                    dyAnchorCustomerVo.setPerTransForm(totalPerTransForm);
                }

                if (totalArrivalsNum > 0){
                    BigDecimal totalPerArrivals = BigDecimal.valueOf(totalArrivalsNum).divide(BigDecimal.valueOf(totalGiftSum),2,BigDecimal.ROUND_HALF_UP);
                    dyAnchorCustomerVo.setPerArrivals(totalPerArrivals);
                }
            }
        }
        return dyAnchorCustomerVo;
    }



    /**
     * 批量删除主播
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
